import requests
tag = {4: '历史', 5: '动作', 10: '悬疑', 11: '剧情', 17: '科幻', 24: '喜剧', 25: '动画'}
tag_id = int(input('请输入电影类别编号：'))
page = int(input('请输入要爬取的页码：'))
url = f'https://movie.douban.com/j/new_search_subjects?sort=U&range=0,10&tags=&start={(page - 1) * 20}&genres={tag[tag_id]}'
headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"}
response = requests.get(url, headers=headers)
content = response.text
with open(f'D:/douban_pachong.text', 'w', encoding='utf-8') as f:
    f.write(content)
print("爬虫完成")

